<?php

namespace app\admin\controller;
use think\Db;

class Index
{
    public function __construct()
    {
        Admin_auth();
    }

    public function index()
    {
        $data = array();
        $menu = array();
        $data = Db::table("webconfig")->where(['id' => 1])->find();
        $data['system'] = php_uname('s');
        $topmenu = Db::table("admin_menu")->where('gid', 0)->whereIn('auth', session('wmo2o_a_auth'))->select();
        if (!empty($topmenu)) {
            foreach ($topmenu as $sub) {
                $sub['sub'] = Db::table("admin_menu")->where('gid', $sub['id'])->whereIn('auth', session('wmo2o_a_auth'))->select();
                Array_push($menu, $sub);
            }
        }
        return view('', ['data' => $data, 'menu' => $menu]);
    }

    public function home()
    {
        $data = array();
        $data = Db::table("webconfig")->where(['id' => 1])->find();
        $data['system'] = php_uname('s');
        return view('', ['data' => $data]);
    }

    public function setting()
    {
        $tab = input("get.tab");
        if (request()->isPost()) {
            $data = input("post.");
            Db::table("webconfig")->where(['id' => 1])->update($data);
        }
        $data = Db::table("webconfig")->where(['id' => 1])->find();
        return view('', ['data' => $data, 'tab' => $tab]);
    }

    public function about()
    {
        if (request()->isPost()) {
            $data = request()->post();
            Db::table('settings')->where('id', 1)->update($data);
            redirect(url('index/about'));
            exit;
        } else {
            $data = Db::table('settings')->where('id', 1)->find();
            return view('',['data'=>$data]);
        }
    }
}
